
/**
 * 封装文字小部件
 * 主要作用是跟随系统主题变化文字颜色和字体大小
 * 这里用到了main里面的默认文字颜色Theme.of(context).primaryColor
 */
import 'package:flutter/material.dart';
import 'package:moonplay/common/app_common.dart';
import 'package:moonplay/common/common_size.dart';
import 'package:moonplay/provide/provide.dart';

class Cptext extends StatelessWidget {
  final String text;
  final TextStyle style;
  final StrutStyle strutStyle;
  final TextAlign textAlign;
  final TextDirection textDirection;
  final Locale locale;
  final bool softWrap;
  final TextOverflow overflow;
  final double textScaleFactor;
  final int maxLines;
  final String semanticsLabel;
  final TextWidthBasis textWidthBasis;

  const Cptext({Key key, this.text, this.style, this.strutStyle, this.textAlign, this.textDirection, this.locale, this.softWrap, this.overflow, this.textScaleFactor, this.maxLines, this.semanticsLabel, this.textWidthBasis}) : super(key: key);

  
  @override
  Widget build(BuildContext context) {
    double _fontSize = style != null && style.fontSize != null ? style.fontSize : AppSize.defaulSize;

    return Provide<FontSizeProvide>(
      builder: (context, child, appSize) {
        double _size = appSize.textSize + _fontSize;
        TextStyle _style = TextStyle(
          fontSize: ScreenUtil().getSp(_size),
          color: style != null ? style.color : Theme.of(context).primaryColor,
          backgroundColor: style != null ? style.backgroundColor : Colors.transparent,
          fontWeight: style != null ? style.fontWeight : FontWeight.normal,
          fontStyle: style != null ? style.fontStyle : FontStyle.normal,
          letterSpacing: style != null ? style.letterSpacing : 0.0,
          wordSpacing: style != null ? style.wordSpacing : 0.0,
          textBaseline: style != null ? style.textBaseline : TextBaseline.ideographic,
        );
        
        return Text(text, 
          style: _style,
          strutStyle: this.strutStyle,
          textAlign: this.textAlign,
          textDirection: this.textDirection,
          locale: this.locale,
          softWrap: this.softWrap,
          overflow: this.overflow,
          textScaleFactor: this.textScaleFactor,
          maxLines: this.maxLines,
          semanticsLabel: this.semanticsLabel,
          textWidthBasis: this.textWidthBasis,
        );
      }
    );
  }
}